package com.eims.sls_app.ui;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.XML;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.MySingleton;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.StringXmlRequest;
import com.android.volley.toolbox.XMLRequest;
import com.contans.view.PayFroresultVo;
import com.eims.sls_app.utils.BaseHelper;
import com.eims.sls_app.view.MyToast;
import com.google.gson.Gson;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import bls.juejin.cn.R;

public class TestActivity extends Activity {
	private TextView tvShow;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.saoma_xplay_pay);
		tvShow = (TextView) findViewById(R.id.tv_saoma_pay);
		tvShow.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.e("TAG", "pName is " + "z");
				getBalllInfo();

			}
		});
	}

	public void get() {
		MySingleton mySingleton = MySingleton.getInstance(TestActivity.this);
		XMLRequest xmlRequest = new XMLRequest("http://01link.igowu123.com/qtjsbf/jc/zjdata/171208009.xml",
				new Response.Listener<XmlPullParser>() {
					@Override
					public void onResponse(XmlPullParser parser) {
						try {
							// 得到当前事件类型
							int eventType = parser.getEventType();

							// Colleague colleague = null;
							while (eventType != XmlPullParser.END_DOCUMENT) {
								switch (eventType) {
								case XmlPullParser.START_DOCUMENT:
									break;
								case XmlPullParser.START_TAG:
									/**
									 * 通过getName判断读到哪个标签, 然后通过nextText获取文本节点值， 或者通过getAttributeValue(i)获取属性节点值
									 */
									String name = parser.getName();
									String id = parser.getAttributeValue(0);
									Log.e("xxxx", id);

									break;
								case XmlPullParser.END_TAG:

									break;
								}
								eventType = parser.next();

							}
						} catch (XmlPullParserException e) {
							e.printStackTrace();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}
				}, new Response.ErrorListener() {
					@Override
					public void onErrorResponse(VolleyError error) {
						Log.e("TAG", error.getMessage(), error);
					}
				});
		xmlRequest.setShouldCache(false);// 是否设置缓存

		mySingleton.addToRequestQueue(xmlRequest);
	}

	public void getBalllInfo() {
		MySingleton mySingleton = MySingleton.getInstance(TestActivity.this);

		StringXmlRequest jsonObjectRequest = new StringXmlRequest(Request.Method.GET,
				"http://01link.igowu123.com/qtjsbf/jc/zjdata/171208009.xml", new Response.Listener<String>() {
					@Override
					public void onResponse(String tn) {

						Log.i("RealTime", "request--------success------" + tn);

						try {
							JSONObject obj = XML.toJSONObject(tn);
							
							Log.e("JSON", obj.toString());

						} catch (JSONException e) {
							System.err.println("xml->json失败" + e.getLocalizedMessage());

						}

						

					}
				}, new Response.ErrorListener() {

					@Override
					public void onErrorResponse(VolleyError error) {
						Log.i("RealTime", "request--------success------" + error);
						MyToast.getToast(TestActivity.this, "获取失败").show();
					}
				}) {
			@Override
			protected Map<String, String> getParams() throws AuthFailureError {

				Map<String, String> params = new HashMap<String, String>();
				// params.put("appid", "0af5281058488ec1784e433f69d45d81");
				// params.put("custNo", "gl00014156");
				// params.put("orderId", attach);

				return params;
			}
		};

		jsonObjectRequest.setShouldCache(false);// 是否设置缓存

		mySingleton.addToRequestQueue(jsonObjectRequest);

	}

}
